<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>axios 调用方法发送请求</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/1.3.6/axios.js"></script>
</head>
<body>
    <button>get</button>
    <button>post</button>
    <script>
        //获取按钮
        let btns = document.querySelectorAll('button');
        //第一个按钮
        btns[0].onclick = async function(){
            // axios.get(url, config);
            let res = await axios.get('http://localhost:3000/song', {
                params: {
                    q: '周'
                },
                headers: {
                    a: 100
                }
            });
            console.log(res);
        }
    
        //第二个按钮
        btns[1].onclick = async function(){
            // axios.post(url, data, config)
            let res = await axios.post('http://localhost:3000/song', {
                name: '我记得',
                singer: '赵雷'
            }, {
                headers: {
                    auth: 'a231251abdce'
                }
            });
            console.log(res);
        }
    </script>
</body>
</html>